// nvue common mixins
import md5Libs from "uview-ui/libs/function/md5"; //引入md5加密方式
const md5 = md5Libs.md5;
import dayjs from 'dayjs'; //引入时间格式化插件 dayjs https://dayjs.fenxianglu.cn/
import {
	SECRETKEY
} from "@/config/index"
const baseUrl = uni.getStorageSync('baseUrl'); //获取接口根路径
const token = uni.getStorageSync("token"); //获取token
export default {
	data() {
		return {

		}
	},
	methods: {
		http(path = "", params = {}, method = "POST") {
			return new Promise((resolve, reject) => {
				uni.request({
					url: `${baseUrl}/${path}?t=${new Date().getTime()}`,
					method: method,
					data: {
						api_token: md5(
							`${path}${SECRETKEY}`
						),
						client_id: 1,
						token,
						...params,
					},
					success: (res) => {
						resolve(res);

					},
					fail: (err) => {
						reject(err);
					},
				});
			});
		},
		linkTo(url, type = 'default') {
			console.log(type)
			if (type === 'switchTab') {
				return uni.switchTab({
					url: url
				});
			}
			if (type === 'back') {
				return uni.navigateTo({});
			}
			if (type === 'redict') {
				return uni.redirectTo({
					url: url
				});
			}
			uni.navigateTo({
				url: url
			})
		}
	}
}
